<template>
  <div id="app">
    <header>
      <div class="header-content">
        <div class="left-content" @click="goToHome">
          <img src="@/assets/logo_3.png" alt="项目 Logo" class="logo" />
          <img
            src="@/assets/logo_character.png"
            alt="新图片"
            class="new-image"
          />
        </div>
        <nav class="nav-container">
          <div class="nav-links">
            <!-- 铜镜鉴古下拉菜单 -->
            <div
              class="nav-dropdown"
              @mouseenter="openDropdown('bronzeMirror')"
              @mouseleave="closeDropdown('bronzeMirror')"
            >
              <div
                class="nav-link dropdown-trigger"
                :class="{ 'active-nav': isBronzeMirrorActive }"
              >
                <img
                  src="@/assets/public-icon1.png"
                  alt="左侧装饰"
                  class="decor-image"
                />
                铜镜鉴古
                <i class="fas fa-chevron-down dropdown-arrow"></i>
              </div>
              <transition name="dropdown-fade">
                <div
                  class="dropdown-menu nav-dropdown-menu"
                  v-show="activeDropdown === 'bronzeMirror'"
                  @mouseenter="cancelCloseDropdown"
                  @mouseleave="closeDropdown('bronzeMirror')"
                >
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isBronzeMirrorPage }"
                    @click.prevent="checkLoginAndNavigate('/bronzemirror')"
                  >
                    青铜鉴定
                  </div>
                  <div
                    class="dropdown-item"
                    :class="{
                      'active-dropdown-item': isBronzeClassificationPage,
                    }"
                    @click="checkLoginAndNavigate('/bronzeclassification')"
                  >
                    分类断代
                  </div>
                </div>
              </transition>
            </div>

            <!-- 青铜宝典下拉菜单 -->
            <div
              class="nav-dropdown"
              @mouseenter="openDropdown('bronzeCodex')"
              @mouseleave="closeDropdown('bronzeCodex')"
            >
              <div
                class="nav-link dropdown-trigger"
                :class="{ 'active-nav': isBronzeCodexActive }"
              >
                青铜宝典
                <i class="fas fa-chevron-down dropdown-arrow"></i>
              </div>
              <transition name="dropdown-fade">
                <div
                  class="dropdown-menu nav-dropdown-menu"
                  v-show="activeDropdown === 'bronzeCodex'"
                  @mouseenter="cancelCloseDropdown"
                  @mouseleave="closeDropdown('bronzeCodex')"
                >
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isBronzeCodexPage }"
                    @click="checkLoginAndNavigate('/bronzecodex')"
                  >
                    青铜图鉴
                  </div>
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isMapPage }"
                    @click="checkLoginAndNavigate('/map')"
                  >
                    地图寻宝
                  </div>
                </div>
              </transition>
            </div>

            <!-- 深入青铜下拉菜单 -->
            <div
              class="nav-dropdown"
              @mouseenter="openDropdown('bronzeGuide')"
              @mouseleave="closeDropdown('bronzeGuide')"
            >
              <div
                class="nav-link dropdown-trigger"
                :class="{ 'active-nav': isBronzeGuideActive }"
              >
                深入青铜
                <i class="fas fa-chevron-down dropdown-arrow"></i>
              </div>
              <transition name="dropdown-fade">
                <div
                  class="dropdown-menu nav-dropdown-menu"
                  v-show="activeDropdown === 'bronzeGuide'"
                  @mouseenter="cancelCloseDropdown"
                  @mouseleave="closeDropdown('bronzeGuide')"
                >
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isBronzeGuidePage }"
                    @click="checkLoginAndNavigate('/bronzeguide')"
                  >
                    学习指南
                  </div>
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isRecogChallengePage }"
                    @click="checkLoginAndNavigate('/recogchallenge')"
                  >
                    知识问答
                  </div>
                </div>
              </transition>
            </div>

            <!-- 三维重建下拉菜单 -->
            <div
              class="nav-dropdown"
              @mouseenter="openDropdown('bronzeRestoration')"
              @mouseleave="closeDropdown('bronzeRestoration')"
            >
              <div
                class="nav-link dropdown-trigger"
                :class="{ 'active-nav': isBronzeRestorationActive }"
              >
                三维重建
                <i class="fas fa-chevron-down dropdown-arrow"></i>
              </div>
              <transition name="dropdown-fade">
                <div
                  class="dropdown-menu nav-dropdown-menu"
                  v-show="activeDropdown === 'bronzeRestoration'"
                  @mouseenter="cancelCloseDropdown"
                  @mouseleave="closeDropdown('bronzeRestoration')"
                >
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isBronzeRestorationPage }"
                    @click="checkLoginAndNavigate('/bronzerestoration')"
                  >
                    模型展示
                  </div>
                  <div
                    class="dropdown-item"
                    :class="{ 'active-dropdown-item': isNerfPage }"
                    @click="checkLoginAndNavigate('/nerf')"
                  >
                    多图建模
                  </div>
                </div>
              </transition>
            </div>

            <!-- 论坛按钮 -->
            <div
              class="nav-link dropdown-trigger"
              :class="{ 'active-nav': isNewsActive }"
              @click="checkLoginAndNavigate('/news')"
            >
              论坛
              <img
                src="@/assets/public-icon2.png"
                alt="右侧装饰"
                class="decor-image"
              />
            </div>
          </div>
        </nav>
        <div class="right-content">
          <div
            class="user-menu-container"
            @mouseenter="openUserMenu"
            @mouseleave="startCloseUserMenuTimer"
          >
            <i class="fas fa-user user-icon" @click="goToProfile"></i>
            <transition name="fade">
              <div
                v-if="showUserMenu"
                class="dropdown-menu"
                @mouseenter="cancelCloseUserMenu"
                @mouseleave="startCloseUserMenuTimer"
              >
                <template v-if="!isLoggedIn">
                  <button
                    class="dropdown-item"
                    style="width: 100%"
                    @click="openRegistrationModal"
                  >
                    注册
                  </button>
                  <button
                    class="dropdown-item"
                    style="width: 100%"
                    @click="openLoginModal"
                  >
                    登录
                  </button>
                </template>
                <template v-else>
                  <button
                    class="dropdown-item"
                    style="width: 100%"
                    @click="logout"
                  >
                    退出
                  </button>
                  <button
                    class="dropdown-item"
                    style="width: 100%"
                    @click="goToAdmin"
                  >
                    管理界面
                  </button>
                </template>
              </div>
            </transition>
          </div>
          <div class="search-container">
            <i class="fas fa-search search-icon" @click="toggleSearchBox"></i>
            <transition name="fade">
              <div v-if="showSearchBox" class="search-box">
                <input
                  type="text"
                  v-model="searchQuery"
                  placeholder="关键词"
                  @keyup.enter="performSearch"
                />
                <button class="close-search-button" @click="closeSearchBox">
                  &times;
                </button>
              </div>
            </transition>
          </div>
        </div>
      </div>
    </header>

    <keep-alive>
      <router-view :is-logged-in="isLoggedIn"></router-view>
    </keep-alive>

    <!-- 注册模态框 -->
    <transition name="fade">
      <div
        v-if="showRegistrationModal"
        class="modal-overlay"
        @click.self="closeRegistrationModal"
      >
        <div class="modal">
          <button @click="closeRegistrationModal" class="close-button">
            &times;
          </button>
          <div class="modal-header">
            <h2>注册</h2>
          </div>
          <div class="modal-body">
            <form @submit.prevent="registerUser" class="modal-form">
              <div class="form-group">
                <label for="username">用户名：</label>
                <input
                  type="text"
                  id="username"
                  v-model="username"
                  required
                  placeholder="请输入用户名"
                />
              </div>
              <div class="form-group">
                <label for="password">密码：</label>
                <input
                  type="password"
                  id="password"
                  v-model="password"
                  required
                  placeholder="请输入密码"
                />
              </div>
              <div class="form-group">
                <label for="captcha">验证码：</label>
                <input
                  type="text"
                  id="captcha"
                  v-model="captcha"
                  required
                  placeholder="请输入验证码"
                />
                <img
                  :src="captchaImageUrl"
                  alt="验证码"
                  @click="refreshCaptcha"
                  class="captcha-image"
                />
              </div>
              <button type="submit" class="submit-button">注册</button>
            </form>
          </div>
        </div>
      </div>
    </transition>

    <!-- 登录模态框 -->
    <transition name="fade">
      <div
        v-if="showLoginModal"
        class="modal-overlay"
        @click.self="closeLoginModal"
      >
        <div class="modal">
          <button @click="closeLoginModal" class="close-button">&times;</button>
          <div class="modal-header">
            <h2>登录</h2>
          </div>
          <div class="modal-body">
            <form @submit.prevent="loginUser" class="modal-form">
              <div class="form-group">
                <label for="login-username">用户名：</label>
                <input
                  type="text"
                  id="login-username"
                  v-model="username"
                  required
                  placeholder="请输入用户名"
                />
              </div>
              <div class="form-group">
                <label for="login-password">密码：</label>
                <input
                  type="password"
                  id="login-password"
                  v-model="password"
                  required
                  placeholder="请输入密码"
                />
              </div>
              <div class="form-group">
                <label for="captcha">验证码：</label>
                <input
                  type="text"
                  id="captcha"
                  v-model="captcha"
                  required
                  placeholder="请输入验证码"
                />
                <img
                  :src="captchaImageUrl"
                  alt="验证码"
                  @click="refreshCaptcha"
                  class="captcha-image"
                />
              </div>
              <button type="submit" class="submit-button">登录</button>
            </form>
          </div>
        </div>
      </div>
    </transition>

    <!-- Bronze AI沟通小页面 -->
    <transition name="slide-fade">
      <div v-if="showChatWindow" class="chat-window">
        <button class="close-button" @click="closeChatWindow">&times;</button>
        <div class="chat-content" ref="chatContent">
          <div
            v-for="(message, index) in messages"
            :key="index"
            class="message"
            :class="message.sender.toLowerCase()"
          >
            <strong>{{ message.sender }}:</strong>
            <span v-html="message.content"></span>
            <div
              v-if="
                index === messages.length - 1 &&
                message.sender === 'You' &&
                isThinking
              "
              class="thinking-indicator"
            >
              <span class="thinking-text">Bronze AI 正在思考中</span>
              <span class="thinking-dots"></span>
            </div>
          </div>
        </div>
        <div class="input-container">
          <input
            v-model="userInput"
            @keyup.enter="sendMessage"
            placeholder="请输入问题..."
          />
          <button @click="sendMessage" :disabled="!userInput.trim()">
            发送
          </button>
        </div>
      </div>
    </transition>

    <!-- 自定义提示框 -->
    <transition name="fade">
      <div v-if="showAlert" class="custom-alert-overlay">
        <div class="custom-alert">
          <button @click="closeAlert" class="alert-close-button">
            &times;
          </button>
          <div class="alert-content">
            <i class="fas fa-exclamation-circle alert-icon"></i>
            <p>{{ alertMessage }}</p>
          </div>
          <div class="alert-buttons">
            <button @click="handleRegister" class="alert-button register">
              立即注册
            </button>
            <button @click="handleLogin" class="alert-button login">
              立即登录
            </button>
          </div>
        </div>
      </div>
    </transition>

    <!-- Bronze AI 按钮 -->
    <button
      class="bronze-ai-button"
      @click="checkLoginAndExecute(openChatWindow)"
    >
      <i class="fas fa-robot"></i>
      <span class="button-text">Bronze AI</span>
      <span class="full-text">古青铜学习小助手</span>
    </button>

    <Footer v-if="$route.path !== '/'" />
  </div>
</template>

<script>
import axios from "axios";
import { marked } from "marked";
import { BASE_URL } from "@/config.js";
import Footer from "./components/Footer.vue";

export default {
  name: "App",
  components: {
    Footer,
  },
  props: {
    isLoggedIn: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    userIsLoggedIn() {
      return this.isLoggedIn;
    },
    userAvatarStyle() {
      return {
        backgroundImage: `url(${this.userAvatar})`,
      };
    },
    // 判断当前路由的计算属性
    currentRoute() {
      return this.$route.path;
    },
    // 判断是否为铜镜鉴古相关页面
    isBronzeMirrorActive() {
      return ["/bronzemirror", "/bronzeclassification"].includes(
        this.currentRoute
      );
    },
    // 判断是否为青铜宝典相关页面
    isBronzeCodexActive() {
      return ["/bronzecodex", "/map"].includes(this.currentRoute);
    },
    // 判断是否为深入青铜相关页面
    isBronzeGuideActive() {
      return ["/bronzeguide", "/recogchallenge"].includes(this.currentRoute);
    },
    // 判断是否为三维重建相关页面
    isBronzeRestorationActive() {
      return ["/bronzerestoration", "/nerf"].includes(this.currentRoute);
    },
    // 判断是否为论坛页面
    isNewsActive() {
      return this.currentRoute === "/news";
    },
    // 判断是否为管理页面
    isAdminActive() {
      return this.currentRoute === "/admin";
    },
    // 判断具体子页面
    isBronzeMirrorPage() {
      return this.currentRoute === "/bronzemirror";
    },
    isBronzeClassificationPage() {
      return this.currentRoute === "/bronzeclassification";
    },
    isBronzeCodexPage() {
      return this.currentRoute === "/bronzecodex";
    },
    isMapPage() {
      return this.currentRoute === "/map";
    },
    isBronzeGuidePage() {
      return this.currentRoute === "/bronzeguide";
    },
    isRecogChallengePage() {
      return this.currentRoute === "/recogchallenge";
    },
    isBronzeRestorationPage() {
      return this.currentRoute === "/bronzerestoration";
    },
    isNerfPage() {
      return this.currentRoute === "/nerf";
    },
  },
  data() {
    return {
      showRegistrationModal: false,
      showLoginModal: false,
      showChatWindow: false,
      username: "",
      password: "",
      isLoggedIn: false,
      userInput: "",
      messages: [
        {
          sender: "Bronze AI",
          content:
            "您好！我是Bronze AI，青铜器知识问答助手，有任何疑问，请随时向我提问！",
        },
      ],
      isThinking: false,
      currentAIResponse: "",
      userAvatar: "@/assets/default_user.jpg",
      showUserMenu: false,
      showSearchBox: false,
      searchQuery: "",
      captcha: "", // 用户输入的验证码
      captchaImageUrl: "", // 验证码图片的 URL
      activeDropdown: null, // 当前激活的下拉菜单
      showAlert: false,
      alertMessage: "",
    };
  },
  methods: {
     openUserMenu() {
    clearTimeout(this.userMenuTimer);
    this.showUserMenu = true;
  },
  
  startCloseUserMenuTimer() {
    this.userMenuTimer = setTimeout(() => {
      this.showUserMenu = false;
    }, 300); // 增加到300ms
  },
  
  cancelCloseUserMenu() {
    clearTimeout(this.userMenuTimer);
  },
  
  closeUserMenu() {
    clearTimeout(this.userMenuTimer);
    this.showUserMenu = false;
  },

    async refreshCaptcha() {
      try {
        const response = await axios.get(
          `${BASE_URL}/captcha`,
          {
            responseType: "blob",
            withCredentials: true, // 确保携带cookie
          }
        );

        const url = URL.createObjectURL(response.data);
        this.captchaImageUrl = url;
      } catch (error) {
        console.error("刷新验证码失败:", error);
        this.captchaImageUrl = null;
      }
    },
    checkLoginAndExecute(func) {
      if (this.isLoggedIn) {
        func();
      } else {
        this.showCustomAlert("请先注册或登录以使用此功能");
      }
    },
    openRegistrationModal() {
      this.showRegistrationModal = true;
      this.closeUserMenu();
    },
    openLoginModal() {
      this.showLoginModal = true;
      this.closeUserMenu();
    },
    closeRegistrationModal() {
      this.showRegistrationModal = false;
    },
    closeLoginModal() {
      this.showLoginModal = false;
    },
    openChatWindow() {
      this.showChatWindow = true;
    },
    closeChatWindow() {
      this.showChatWindow = false;
    },
    async registerUser() {
      const response = await axios.get(
        `${BASE_URL}/verify_captcha`,
        {
          params: {
            captcha: this.captcha.trim().toUpperCase(),
          },
          withCredentials: true,
        }
      );
      console.log(response.data);

      // 根据后端返回的结果处理
      if (response.data.success) {
        // 验证码正确
        try {
          const response = await axios.post(`${BASE_URL}/api/register`, {
            username: this.username,
            password: this.password,
          });
          if (response.data.success) {
            this.updateUserId(response.data.id);
            this.isLoggedIn = true;
            alert("注册成功！");
            this.showRegistrationModal = false;
          } else {
            alert("注册失败：" + response.data.message);
          }
        } catch (error) {
          console.error("注册错误", error);
          alert("注册出错，请稍后再试");
        }
      } else {
        // 验证码错误
        alert("验证码错误");
        // 可以在这里提示用户重新输入
        this.refreshCaptcha(); // 刷新验证码
      }
    },
    async loginUser() {
      const response = await axios.get(
        `${BASE_URL}/verify_captcha`,
        {
          params: {
            captcha: this.captcha.trim().toUpperCase(),
          },
          withCredentials: true,
        }
      );
      console.log(response.data);

      // 根据后端返回的结果处理
      if (response.data.success) {
        // 验证码正确
        try {
          const response = await axios.post(`${BASE_URL}/api/login`, {
            username: this.username,
            password: this.password,
          });
          if (response.data.success) {
            this.updateUserId(response.data.id);
            console.log("User ID stored after login:", this.storedUserId);
            this.isLoggedIn = true;
            alert("登录成功！");
            this.showLoginModal = false;
            this.$emit("login-success");
          } else {
            alert("登录失败：" + response.data.message);
          }
        } catch (error) {
          console.error("登录错误", error);
          alert("登录出错，请稍后再试");
        }
      } else {
        // 验证码错误
        alert("验证码错误");
        // 可以在这里提示用户重新输入
        this.refreshCaptcha(); // 刷新验证码
      }
    },
    logout() {
      this.isLoggedIn = false;
      this.userId = null;
      this.username = "";
      this.password = "";
      localStorage.removeItem("userId");
      alert("已退出登录");
      this.closeUserMenu();
    },
    checkLoginStatus() {
      const userId = localStorage.getItem("userId");
      if (userId) {
        this.isLoggedIn = true;
        this.userId = userId;
      } else {
        this.isLoggedIn = false;
        this.userId = null;
      }
    },
    updateUserId(newId) {
      localStorage.setItem("userId", newId.toString());
      this.storedUserId = newId.toString();
      console.log("Updated userId:", this.storedUserId);
    },
    async sendMessage() {
      if (!this.userInput.trim()) return;

      this.messages.push({ sender: "You", content: this.userInput });
      const userMessage = this.userInput;
      this.userInput = "";
      this.isThinking = true;

      try {
        const response = await fetch(`${BASE_URL}/api3/chat`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ message: userMessage }),
        });

        const reader = response.body.getReader();
        const decoder = new TextDecoder();

        this.currentAIResponse = "";
        this.messages.push({ sender: "Bronze AI", content: "" });

        while (true) {
          const { value, done } = await reader.read();
          if (done) break;

          const decodedChunk = decoder.decode(value, { stream: true });
          const lines = decodedChunk.split("\n");

          for (const line of lines) {
            if (line.startsWith("data: ")) {
              const data = JSON.parse(line.slice(6));
              this.currentAIResponse += data.content;

              this.messages[this.messages.length - 1].content = marked(
                this.currentAIResponse
              );
              this.$nextTick(() => {
                this.scrollToBottom();
              });
            }
          }
        }

        this.isThinking = false;
      } catch (error) {
        console.error("Error:", error);
        this.isThinking = false;
        this.messages.push({ sender: "系统", content: "获取回复时出错。" });
      }
    },

    scrollToBottom() {
      const chatContent = this.$refs.chatContent;
      chatContent.scrollTop = chatContent.scrollHeight;
    },

    openUserMenu() {
      this.showUserMenu = true;
    },
    closeUserMenu() {
      this.showUserMenu = false;
    },
    toggleSearchBox() {
      this.showSearchBox = !this.showSearchBox;
    },
    closeSearchBox() {
      this.showSearchBox = false;
    },
    goToHome() {
      this.$router.push("/");
    },
    goToProfile() {
      this.$router.push("/profile");
      this.closeUserMenu();
    },
    openDropdown(dropdownName) {
      this.activeDropdown = dropdownName;
      this.dropdownTimer && clearTimeout(this.dropdownTimer);
    },
    closeDropdown(dropdownName) {
      this.dropdownTimer = setTimeout(() => {
        if (this.activeDropdown === dropdownName) {
          this.activeDropdown = null;
        }
      }, 200);
    },
    cancelCloseDropdown() {
      clearTimeout(this.dropdownTimer);
    },
    performSearch() {
      const query = this.searchQuery.trim();
      const routes = {
        首页: "/",
        论坛: "/news",
        我的: "/profile",
        关于: "/readme",
        铜镜鉴古: "/",
        青铜宝典: "/",
        深入青铜: "/",
        三维重建: "/",
        青铜鉴定: "/bronzemirror",
        分类断代: "/bronzeclassification",
        青铜图鉴: "/bronzecodex",
        地图寻宝: "/map",
        学习指南: "/bronzeguide",
        知识问答: "/recogchallenge",
        模型展示: "/bronzerestoration",
        多图建模: "/nerf",
        个人博物馆: "/collectedartifacts",
        收藏题集: "/collectedquestions",
        收藏动态: "/collectednews",
      };
      if (routes[query]) {
        this.$router.push(routes[query]);
        this.closeSearchBox();
      } else {
        alert("未找到匹配的导航项");
      }
    },
    goToAdmin() {
      this.$router.push("/admin");
      this.closeUserMenu();
    },
    checkLoginAndNavigate(path) {
      if (this.isLoggedIn) {
        this.$router.push(path);
      } else {
        this.showCustomAlert("请先注册或登录以使用此功能");
      }
    },
    showCustomAlert(message) {
      this.alertMessage = message;
      this.showAlert = true;
    },
    closeAlert() {
      this.showAlert = false;
    },
    handleRegister() {
      this.showAlert = false;
      this.openRegistrationModal();
    },
    handleLogin() {
      this.showAlert = false;
      this.openLoginModal();
    },
  },
  mounted() {
    this.checkLoginStatus();
    this.refreshCaptcha(); // 初始加载验证码图片
  },
};
</script>

<style>
body {
  margin: 0;
  padding: 0;
  background-color: #080808;
  font-family: "SimSun", "STSong", serif;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* 允许垂直滚动 */
}

html {
  height: 100%;
}

#app {
  min-height: 100vh; /* 设置视口的最小高度 */
  display: flex;
  flex-direction: column;
  background-color: #000000; /* 设置整体背景为全黑 */
}

header {
  background-color: rgba(0, 0, 0, 0.8); /* 设置为半透明黑色 */
  color: white;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 1000;
  padding: 10px 20px;
  border-bottom: 1px solid gray;
  box-sizing: border-box;
  overflow: visible; /* 确保下拉菜单不被裁剪 */
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: center; /* Center content */
  position: relative; /* For absolute positioning of nav-container */
}

.left-content,
.nav-container,
.right-content {
  display: flex;
  align-items: center;
}

.left-content,
.right-content {
  flex: 1;
}

.left-content {
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.left-content:hover {
  opacity: 0.8;
}

.nav-container {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  overflow: visible; /* 确保下拉菜单不被裁剪 */
  /* Removed flex: 2 */
}

.logo {
  height: 40px;
  border-radius: 10px;
  transition: transform 0.5s ease, box-shadow 0.5s ease;
}

.new-image {
  height: 40px;
  margin-left: 10px; /* Added margin for better spacing */
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible; /* 确保下拉菜单不被裁剪 */
}

.nav-link {
  display: flex; /* Add flex to align items */
  align-items: center; /* Vertically center items */
  font-size: 22px; /* 增大字体大小 */
  color: #f3d68b;
  text-decoration: none;
  padding: 0 20px;
  margin: 0 15px;
  position: relative;
  transition: color 0.3s ease, transform 0.3s ease; /* 添加颜色和缩放的过渡效果 */
  font-family: "KaiTi", "SimSun", "STSong", serif;
  white-space: nowrap; /* 防止文字换行 */
}

.nav-link:hover {
  color: #d4af37; /* 更深的金色 */
  transform: scale(1.01); /* 放大10% */
}

/* 当前页面导航高亮样式 */
.nav-link.active-nav {
  font-weight: bold;
  color: #ffd700; /* 更亮的金色 */
  transform: scale(1.02); /* 稍微放大 */
}

.nav-link.active-nav:hover {
  color: #ffd700; /* 保持高亮状态的颜色 */
}

/* 确保下拉箭头不受下划线影响 */
.nav-link.active-nav .dropdown-arrow {
  text-decoration: none;
}

/* 装饰图片样式 */
.decor-image {
  height: 20px; /* 根据需要调整图片高度 */
  margin: 0 5px; /* 调整图片与文字之间的间距 */
  vertical-align: middle; /* 垂直居中对齐 */
}

/* 确保装饰图片不受下划线影响 */
.nav-link.active-nav .decor-image {
  text-decoration: none;
}

.nav-link:hover .decor-image {
  transform: scale(1.1);
  transition: transform 0.3s ease;
}

/* 下拉菜单样式 */
.nav-dropdown {
  position: relative;
  display: inline-block;
  z-index: 1002;
  min-width: 100px;
  text-align: center;
}

.dropdown-trigger {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.dropdown-arrow {
  font-size: 12px;
  transition: transform 0.3s ease;
}

.nav-dropdown:hover .dropdown-arrow {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #2e2e2e;
  border: 1px solid #555;
  border-radius: 10px;
  padding: 10px 0;
  z-index: 1001;
  min-width: 150px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  margin-top: 5px;
  transform-origin: top center;
}

.dropdown-fade-enter-active,
.dropdown-fade-leave-active {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.dropdown-fade-enter-from,
.dropdown-fade-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}

.nav-dropdown-menu .dropdown-item {
  display: block;
  padding: 10px 20px;
  color: #f3d68b;
  text-decoration: none;
  font-size: 16px;
  transition: background 0.3s ease, color 0.3s ease;
  text-align: center;
}

.nav-dropdown-menu .dropdown-item:hover {
  background: #f3d68b;
  color: #2e2e2e;
  text-decoration: none;
}

/* 下拉菜单项当前页面高亮样式 */
.nav-dropdown-menu .dropdown-item.active-dropdown-item {
  font-weight: bold;
  background: #f3d68b;
  color: #2e2e2e;
}

.nav-dropdown-menu .dropdown-item.active-dropdown-item:hover {
  background: #ffd700;
  color: #2e2e2e;
}

.right-content {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
}

.user-menu,
.search-container {
  position: relative;
  margin-left: 15px; /* Added margin to separate icons */
}

.user-icon,
.search-icon {
  font-size: 24px;
  color: #f3d68b;
  cursor: pointer;
  transition: transform 0.3s ease, color 0.3s ease;
}

.user-icon:hover,
.search-icon:hover {
  transform: scale(1.1);
  color: #ffd700;
}

.dropdown-menu {
  position: absolute;
  top: 40px;
  right: 0;
  background: #2e2e2e;
  border: 1px solid #555;
  border-radius: 10px;
  padding: 10px 0;
  z-index: 1000;
  animation: dropdownFade 0.3s ease;
  min-width: 120px; /* Ensure minimum width */
}

.dropdown-item {
  background: none;
  border: none;
  text-align: left;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 16px;
  color: #f3d68b;
  transition: background 0.3s ease;
}

.dropdown-item:hover {
  background: #f3d68b;
  color: white;
}

.search-container {
  position: relative;
  margin-left: 15px;
}

.search-box {
  position: absolute;
  top: 40px;
  right: 0;
  background: #2e2e2e;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  animation: searchFade 0.3s ease;
  z-index: 1000;
  width: 260px; /* 稍微增加宽度，给关闭按钮留出空间 */
}

.close-search-button {
  position: absolute;
  top: 50%;
  right: 15px; /* 调整为离右边框有更大的间距 */
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  color: #f3d68b;
  cursor: pointer;
  padding: 0;
  margin: 0;
  z-index: 1;
}

.search-box input {
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 7px 10px; /* 增加左右内边距 */
  font-size: 16px;
  width: 100%;
  transition: border 0.3s ease;
  background: #1e1e1e;
  color: #f3d68b;
  padding-right: 200px; /* 给关闭按钮留出更多空间 */
}

.search-box input::placeholder {
  color: #b3a369;
  opacity: 1;
}

.modal-form input {
  width: 200px; /* 保持固定宽度 */
  padding: 10px 10px; /* 增加左右内边距 */
  border-radius: 5px;
  border: 1px solid #555;
  background: #2e2e2e;
  color: #f3d68b;
  font-size: 16px;
  box-sizing: border-box;
}

.modal-form input::placeholder {
  color: #b3a369;
  opacity: 1;
}

.search-box input::placeholder {
  color: #b3a369;
  opacity: 1;
}

.search-box input:focus {
  outline: none;
  border-color: #f3d68b;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 8, 8, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1002; /* Ensure modals are above header */
}

.modal {
  position: relative;
  background: #1e1e1e;
  padding: 30px;
  border-radius: 10px;
  width: 90%; /* 调整为更宽的百分比 */
  max-width: 500px; /* 设置最大宽度 */
  color: #f3d68b;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center; /* Center content horizontally */
}

.modal-header h2 {
  margin-top: 0;
  font-family: "KaiTi", "SimSun", "STSong", serif;
  text-align: center;
}

.modal-body {
  margin-top: 20px;
  width: 100%;
}

.modal-form {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.form-group {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  width: 100%; /* 确保整个表单宽度一致 */
}

.form-group label {
  width: 100px; /* 设置固定的宽度 */
  margin-right: 10px;
  text-align: right;
  font-size: 16px;
}

.form-group input {
  flex-grow: 1; /* 让输入框宽度自适应 */
  padding: 10px;
  border-radius: 5px;
  border: 1px solid #555;
  background: #2e2e2e;
  color: #f3d68b;
  font-size: 16px;
  box-sizing: border-box;
}

.submit-button {
  background: linear-gradient(45deg, #8b5e3c, #5d3b1e);
  color: white;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  padding: 10px 20px;
  font-size: 17px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
  margin-top: 20px; /* 增加顶部外边距 */
}

.submit-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #f3d68b;
  transition: color 0.3s ease;
}

.close-button:hover {
  color: #e74c3c;
}

/* Bronze AI 按钮样式 */
.bronze-ai-button {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 15px 20px;
  background: linear-gradient(135deg, #8b5e3c, #5d3b1e);
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 15px;
  font-weight: bold;
  z-index: 1000;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 120px; /* 设置最小宽度保证文字显示 */
}

.bronze-ai-button .button-text {
  display: inline; /* 默认显示文字 */
  white-space: nowrap;
  transition: all 0.3s ease;
  margin-left: 10px;
}

.bronze-ai-button .full-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.3s ease, width 0.3s ease;
  margin-left: 0;
}

.bronze-ai-button:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.bronze-ai-button:hover .button-text {
  opacity: 1; /* 保留“Bronze AI” */
  width: auto;
  margin-left: 10px;
}

.bronze-ai-button:hover .full-text {
  opacity: 1;
  width: auto;
  margin-left: 10px;
}

.bronze-ai-button i {
  font-size: 20px;
  transition: transform 0.3s ease;
}

.bronze-ai-button:hover i {
  transform: rotate(15deg);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .bronze-ai-button {
    bottom: 20px;
    right: 20px;
    padding: 12px 15px;
    min-width: 100px;
    font-size: 14px;
  }

  .bronze-ai-button i {
    font-size: 18px;
  }

  .bronze-ai-button .button-text {
    font-size: 14px;
  }
}
.chat-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 500px;
  max-height: calc(100vh - 120px);
  background: #1e1e1e;
  border: none;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  z-index: 1001;
  overflow: hidden;
  transition: all 0.3s ease;
}

.chat-content {
  flex-grow: 1;
  padding: 25px 15px 15px 15px;
  overflow-y: auto;
  background: #2e2e2e;
}

.message {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 80%;
  animation: messageAppear 0.5s ease;
  color: #f3d68b;
}

.message.you {
  background-color: #3e3e3e;
  align-self: flex-end;
  margin-left: auto;
}

.message.bronze.ai {
  background-color: #4e4e4e;
  align-self: flex-start;
  margin-right: auto;
}

.input-container {
  display: flex;
  padding: 15px;
  background: #1e1e1e;
}

.input-container input {
  flex-grow: 1;
  padding: 12px;
  border: 2px solid #8b5e3c;
  border-radius: 25px;
  margin-right: 10px;
  background: #2e2e2e;
  color: #f3d68b;
  font-size: 16px;
  box-sizing: border-box;
}

.input-container input::placeholder {
  color: #b3a369; /* Set a consistent placeholder color */
  opacity: 1; /* Ensure placeholder is fully visible */
}

.input-container button {
  padding: 12px 20px;
  background: linear-gradient(45deg, #8b5e3c, #5d3b1e);
  color: white;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.input-container button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dropdownFade {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes searchFade {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes underlineExpand {
  from {
    width: 0;
    left: 50%;
  }
  to {
    width: 100%;
    left: 0;
  }
}

/* 下拉菜单过渡动画 */
.dropdown-fade-enter-active,
.dropdown-fade-leave-active {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.dropdown-fade-enter-from,
.dropdown-fade-leave-to {
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
}

@media (max-width: 768px) {
  header {
    padding: 10px;
  }

  .header-content {
    flex-direction: column;
    align-items: center;
  }

  .left-content,
  .nav-container,
  .right-content {
    width: 100%;
    justify-content: center;
  }

  .logo,
  .new-image {
    height: 30px;
    margin: 5px;
  }

  .nav-links {
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    margin-top: 30px;
    flex-wrap: wrap;
  }

  .nav-link {
    font-size: 16px;
    padding: 10px;
    margin: 5px;
  }

  .right-content {
    margin-top: 10px;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 10px;
  }

  .user-menu,
  .search-container {
    margin-left: 0;
  }

  .user-icon,
  .search-icon {
    font-size: 20px;
  }

  .dropdown-menu {
    top: 45px;
  }

  .search-box {
    width: 240px;
  }

  .search-box input {
    padding-right: 180px;
  }

  .close-search-button {
    right: 10px;
  }

  .chat-window {
    width: 90%;
    right: 5%;
    left: 5%;
  }

  .bronze-ai-button {
    bottom: 10px;
    right: 10px;
    padding: 12px 20px;
    font-size: 16px;
  }

  .left-content {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }

  .new-image {
    margin-left: 0;
    height: 30px;
  }

  .nav-container {
    margin-top: 10px;
    flex: 1;
  }

  .header-content {
    flex-wrap: wrap;
  }

  .search-box input {
    width: 150px;
    padding-right: 35px; /* 增加右侧内边距以适应关闭按钮 */
  }

  .search-container {
    margin-left: 0;
  }

  .decor-image {
    height: 15px; /* 小屏幕下调整图片高度 */
    margin: 0 3px;
  }

  .dropdown-menu {
    min-width: 100px; /* Adjusted for smaller screens */
  }

  /* 移动端下拉菜单样式 */
  .nav-dropdown {
    position: static;
    z-index: auto;
  }

  .nav-dropdown-menu {
    position: static;
    transform: none;
    background: #1e1e1e;
    border: none;
    border-radius: 0;
    margin-top: 10px;
    box-shadow: none;
    z-index: auto;
    left: auto;
    transform-origin: top center;
  }

  .nav-dropdown-menu .dropdown-item {
    padding: 8px 15px;
    font-size: 14px;
  }
}

.captcha-image {
  height: 40px; /* 设置验证码图片的高度 */
  border-radius: 8px; /* 添加圆角 */
  cursor: pointer; /* 鼠标悬停时显示手型光标 */
  transition: opacity 0.3s ease; /* 添加透明度过渡效果 */
  margin-left: 10px; /* 与输入框的间距 */
}

.captcha-image:hover {
  opacity: 0.8; /* 鼠标悬停时降低透明度 */
}

/* 自定义提示框样式 */
.custom-alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.alert-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  color: #f3d68b;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
  padding: 0;
  line-height: 1;
}

.alert-close-button:hover {
  background: rgba(243, 214, 139, 0.1);
  transform: rotate(90deg);
}

.custom-alert {
  background: #2e2e2e;
  border-radius: 15px;
  padding: 25px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border: 1px solid #f3d68b;
  animation: alertAppear 0.3s ease;
  position: relative; /* 添加这行以支持关闭按钮的绝对定位 */
}

.alert-content {
  display: flex;
  align-items: center;
  margin-bottom: 25px;
  color: #f3d68b;
}

.alert-buttons {
  display: flex;
  gap: 15px;
  justify-content: space-between;
}

.alert-icon {
  font-size: 24px;
  margin-right: 15px;
  color: #f3d68b;
}

.alert-content p {
  font-size: 16px;
  margin: 0;
  line-height: 1.5;
}

.alert-button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.alert-button.register {
  background: linear-gradient(45deg, #8b5e3c, #5d3b1e);
}

.alert-button.login {
  background: linear-gradient(45deg, #d4af37, #b8860b);
}

.alert-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  opacity: 0.9;
}

.alert-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes alertAppear {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
</style>
